package tools;

public final class CheckArgument {
    
    private static final int MAX_PORT_NUMBER = 65535;
    
    private CheckArgument() {
        //prevent instantiation
    }
    
    public static int isValidPort(final String portString) {
        int result = 0;
        try {
            result = Integer.parseInt(portString);
        } catch (NumberFormatException e) {
            Log.err("Not valid integer for port number: " + e.getMessage());
            errorClose();
        }
        if (result < 1 || result > MAX_PORT_NUMBER) {
            Log.err("Port number must be between 1 and 65535, inclusive.");
            errorClose();
        }
        return result;
    }
    
    private static void errorClose() {
        Log.out("Program closed.");
        System.exit(1);
    }

}
